
<template>
   
  <el-checkbox-group v-model="currentValue">
    <el-checkbox :id="id" :label="item.optname" v-for="(item,index) in optionNew" :key="index" :disabled="disabled"></el-checkbox>
  </el-checkbox-group>
    
</template>
 
<script>
    export default {
        props:['options','value','label','name','data','id','isreadonly'],
        name: "input-checkbox-group",
        data(){
            return {
                currentValue:this.value,
                optionNew:[],
                disabled:this.isreadonly=='Y'? true:false,
                pId:"",
                cId:""
            }
        },
        created(){
            console.log("checkgroup-ddjdjdjdjd==================="+this.disabled+"="+this.isreadonly)
          this.setData();
            
        },
        methods:{
            setData(){
                let ids=this.id.split(".");
                if(ids.length>1){
                    let p=ids[0]; 
                    let id_=ids[1];
                    this.pId=p;
                    this.cId=id_;
                //  this.currentValue=this.data[p][id_]=="Y"||this.data[p][id_]=="是" ? true:false;
                    this.currentValue=unescape(this.data[p][id_]).split(",");
                }
                this.optionNew=[];
                for(let i=0;i<this.options.length;i++){
                    if(this.options[i].optvalue){
                        this.optionNew.push(this.options[i])
                    }
                }
            }
        },
        watch:{
            currentValue: function (val) { //currentValue值变动就向父组件传值
                let data={};
                data.id=this.id;
                data.val=val;

                let vals="";
                for(let i=0;i<val.length;i++){
                    if(val[i]!="false"){
                        vals=vals=="" ? val[i]:vals+","+val[i];
                    }
                }
                data.val=vals;
                console.log("111111111111111111111111111111111111111111111");
                console.log(vals);
                //this.$emit('input',JSON.stringify(data));
                //this.$emit('on-change',JSON.stringify(data));
                this.$set(this.data[this.pId],this.cId,vals);
            },
            value:function (val) { //对值进行验证
                
            },
            data:{
                handler: function (newVal) {
                    console.log("data已经改变------")
                    this.setData()
                },      
                deep: true    //深度监听
            }
        }
    }
</script>
<style scoped>
.formitem{
    margin-left:35px;
}
.formitem2{
    margin-left:10px;
}
.el-checkbox{
    margin-right:10px;
}

</style>
<style >
.el-checkbox__input.is-disabled+span.el-checkbox__label{
  color:#606266;
}
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner{
  background-color: #409EFF !important;
  border-color: #409EFF !important;
}
.el-checkbox__input.is-disabled+span.el-checkbox__label{
  
  color:#606266 !important;
}
</style>